home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 July / EnigmA AMIGA RUN 20 (1997)(G.R. Edizioni)(IT)[!][issue 1997-07 & 08][EAR-CD IV].iso / earcd / misc / emu / d32.lha / d32 / Emulator Manual < prev    next >
Text File  |  1997-02-28  |  20KB  |  477 lines

  1.  
  2.                           The 6809 Emulator
  3.                     A design and development tool
  4.                        (C) Steven Goodwin 1994-7
  5.  
  6. Abstract
  7.  
  8. A complete system for writting, running, and debugging machine code to
  9. be run on the 6809e processor  (the fore-runner to the Amiga's 68000).
  10. It  includes  an  assembler,  very  fast  emulator  system,  and  full
  11. development GUI.
  12.  
  13.  
  14.                             -- Comments --
  15.  
  16. From the first line I'll admit it...this is my excuse to start work on
  17. a Dragon emulator! Why?  You  might  ask.  Well,  primarily, because I
  18. loved the machine. It had  the  nicest  processor  I've ever worked on
  19. (except the 68000 :-) ) and I even  enjoyed its brand of BASIC! It's a
  20. shame the Dragon never really caught on.  It was a very good computer.
  21. Unfortunately, it had no lower  case  letters  - only inverse text. It
  22. was this  (coupled  with  the  slightly  too  bright  green background
  23. colour) that caused  it  to  fail  in  the  marketplace,  in my humble
  24. opinion. But, in attempt  to  re-live  those  days,  I started work on
  25. this.
  26.  
  27.    However, this is a  6809  Emulator  -  NOT  A DRAGON EMULATOR. It's
  28. purpose to simulate the running  of  the  processor code, not programs
  29. written for the Dragon.  There  is  a  difference:  none of the Dragon
  30. specific hardware is emulated.
  31.  
  32.    So, what does  the  6809  Emulator  do?  Primarily,  it permits the
  33. development of machine code software  to  run in a virtual environment
  34. under the control of your  Amiga.  The  reason  being it is easier and
  35. safer to do so. Knowing that  any  'endless loops' can be aborted, and
  36. the stack/registers/memory can be inspected.  This  makes it ideal for
  37. students learning a simple (!!?!?!)  machine  code language (or anyone
  38. who doesn't want the  hassle  of  link  libraries,  DLL's or operating
  39. system  calls).  It  is  also  ideal  for  designing  software  for  a
  40. microprocessor controlled system.  You  can  run  and  test the system
  41. under the emulator, and when  complete,  the  code can burnt in EPROM.
  42. Incidentally, it is not too  difficult  to  extend  this idea to build
  43. your own micro-computer! I kid you not.
  44.  
  45.  
  46.                         -- Copyright Notice --
  47.  
  48. This software, and all its associated  documents, is copyright 1997 by
  49. Steven Goodwin. The version provided here may be freely distributed as
  50. long as no files  are  edited  or  deleted,  and  the copyright notice
  51. contained herein is not modified. No warranties, implied or otherwise,
  52. are given and this software  is  used  at  the  users own risk, and no
  53. liability can be accepted for  any  damaged caused, either directly or
  54. indirectly, from this software.
  55.  
  56.  
  57.                            -- Operation --
  58.  
  59. There are two halves:
  60.  
  61. 1) ASA - An assembler to  produce  6809 op-codes from their associated
  62. meumonics. Its  actions  are  dealt  with  in  a  separate  document -
  63. ASA_Manual.doc - also on this disc.
  64.  
  65. 2) The Emulator -  This  runs  a  virtual  6809  processor inside your
  66. Amiga. It is fronted by  a  full  GUI  that  allows easy access to the
  67. registers, condition codes and memory.
  68.  
  69.  
  70. The main emulator  is  controlled  by  a  task  bar  with  a number of
  71. buttons. Each button  opens  a  window  pertaining  to  that task. The
  72. buttons are:
  73.  
  74.                                - Load -
  75.  
  76. This is a generic load requester, and can load any of the following:
  77.  
  78. i) 6809e snapshots - complete memory map, and details of the registers
  79. and condition flags.
  80. ii) Assembler snapshots - as produced by ASA.
  81. iii) Raw data
  82.  
  83.    The software will deduce from the file which type it is looking at,
  84. and load it accordingly. If  it  can  not  deduce  the type it will be
  85. loaded as raw data, and you will be prompted for a start address.
  86.  
  87.  
  88.                                - Save -
  89.  
  90. This opens a small window. From here you can save:
  91.  
  92. i) 6809e snapshot.
  93. ii) Raw memory. You  can  then  proceed  to  enter  the  start and end
  94. points.
  95. iii) Disassembly. Also takes  start  and  end  points, but  produces a
  96. disassembled listed of the memory between the locations specified.
  97.  
  98.    The lower text requester accepts a  file  name and path, whilst the
  99. button on its right will open  a  file  requester and enter the chosen
  100. file name into this gadget.
  101.  
  102.    Above the filename requester are two other text gadgets. These take
  103. the start  and  end  addresses  (inclusive)  of  the  raw  memory,  or
  104. disassembly, block that will be saved to disk.
  105.  
  106.  
  107.                              - Hex View -
  108.  
  109. Produces a scrolling list that covers  the entire 64K memory map. Each
  110. line shows 8 bytes of memory that  can be grouped as bytes, words (two
  111. bytes), integers  (also  two  bytes,  but  displayed  in  decimal) and
  112. characters. In the case  of  the  latter, any non-printable characters
  113. are shown as a dot.
  114.  
  115.    The list can be re-positioned  by  using  the  slider bar, or arrow
  116. buttons. In addition, the text  requester  beneath  the list will take
  117. you to that specific  address.  Upon  pressing  return (or hitting the
  118. 'Goto Addr' button on  its  left)  the  list  will  redraw  at the new
  119. position. The 'Goto PC' will jump directly  to the line of the current
  120. program counter.
  121.  
  122.    You can  open  several  hex  view  windows  at  once,  each showing
  123. different areas of memory.
  124.  
  125.  
  126.                              - Disassembly -
  127.  
  128. This window shows a  disassembled  version  of  the current memory. It
  129. functions in a similar fashion to the  hex view window, insomuch as it
  130. has the 'Goto Addr' and  'Goto  PC'  functions,  but the nature of the
  131. window makes it slightly more difficult to control. Here's why.
  132.  
  133.    The contents of  the  scrolling  list  will  start  at a particular
  134. address, and disassemble memory  until  it  reaches  the bottom of the
  135. list box. The number of assembly  lines it produces will vary, because
  136. each 6809 instruction can occupy a variable number of bytes (between 1
  137. and 4). It is not  therefore  sufficient  to  say  one screen holds 20
  138. instructions. So, when scrolling  the  list (particularly upwards) you
  139. might find the window starts  at  an  address that lies inside another
  140. instruction, and incorrect or illegal  instructions appear. To rectify
  141. this, move the list one byte a  time  (using the arrow buttons, or the
  142. text requester) until the instructions make sense. Unfortunately, this
  143. only comes with experience.
  144.  
  145.    Like hex view windows, you can  open several disassembly windows at
  146. once, if you so wish.
  147.  
  148.  
  149.                             - Registers -
  150.  
  151. This window covers several areas, and is usually open for the entirety
  152. of your work. On the left hand  side are the main 6809 registers. Each
  153. can be  altered  as  required,  by  inputted  the  required  values in
  154. decimal, hexadecimal (with the  '$'  prefix)  or  binary (with the '%'
  155. prefix). After changing any  register  it  is  polite to press return!
  156. This has no relation on performance, but in the case of the PC it will
  157. update the disassembled  instruction  in  the  central  portion of the
  158. window.
  159.  
  160.    On the right is  the  condition  codes  (CC)  register,  given as a
  161. series of check boxes.  A  tick  indicates  the  flag  is set. You can
  162. manipulate these at will, also.
  163.  
  164.    Finally, the far right  has  a  series  of  buttons.  'Asm' opens a
  165. disassembly window and 'Hex'  opens  a  hex  view  window. 'Step' will
  166. execute the instruction at  the  current  program counter. 'Exec' will
  167. execute code on the  virtual  6809  until  a  terminating condition is
  168. reached. That is:
  169.  
  170. 1) The stack is exhausted, and an RTS is reached.
  171. 2) The 'Help' key is pressed.
  172. 3) A breakpoint is reached (see later)
  173.  
  174. Note: To improve the  emulators'  speed  the  help  key is detected by
  175. reading the  keyboard  directly.  This  means  that  if  your keyboard
  176. doesn't produce $41 on a key down  of the help key, the emulator won't
  177. stop. You should  then  either  find  which  key  does correspond...or
  178. register the 6809 Emulator to gain  access  to prefs, which allows you
  179. to change it.
  180.  
  181.    Before every 'exec' or 'step' command every register is copied into
  182. memory ready for the  assembler  to  use.  Similarly  when the command
  183. completes, the entire display is updated, correcting the values in the
  184. registers, and any of the data  shown  in the hex view, disassembly or
  185. stack windows.
  186.  
  187.  
  188. Important Note: Stack Base
  189.  
  190.    This is not a real register.  This  is my creation for allowing the
  191. emulator to determine when the assembler routine has completed. When a
  192. subroutine exits (with  an  RTS  instruction),  the  return address is
  193. popped off the stack, and  the  processor  then jumps to this address.
  194. However, when using the  stack  base  register,  the virtual processor
  195. will exit emulation if the stack pointer  has returned to the value of
  196. the stack base. You might like to think of it as a return address that
  197. points to the GUI environment.
  198.  
  199.  
  200.                               - Stacks -
  201.  
  202. This window shows both system and  user stacks, with the stack pointer
  203. and each return address shown thus:
  204.  
  205. $7FBC : $4E20
  206.  
  207.   Where $7FBC is the memory location  of  the  stack, and $4E20 is the
  208. return address that will be used. The return address can be altered by
  209. using the text requester, if desired.  Each  stack is shown as a list,
  210. where the address at the top is the current stack pointer.
  211.  
  212.  
  213.                            - Memory Edit -
  214.  
  215. This is a quick and easy  method  for  reading information out of, and
  216. putting information back into, memory. It  acts like the Peek and Poke
  217. commands.
  218.  
  219.    The basic window has  a  'Location'  requester (which indicates the
  220. memory location, from 0 to 65535), and a 'Data' requester (for numeric
  221. or string data). Below this  are  a  set  of  buttons, arranged in two
  222. rows.
  223.  
  224.    The top row  is  labelled  'Write'  and  will  place  the data into
  225. memory, starting from the location  given.  A 'null' string means that
  226. the text string will automatically  be  appended with a null character
  227. (zero) before being written.
  228.  
  229.    The bottom row is to 'Read'  data,  and  will extract data from the
  230. memory location given and place it in the 'data' requester.
  231.  
  232.    In both cases, the machine acts  like a little endian machine. This
  233. (rather fancy phrase) means  that  if  the  number  12 is written into
  234. memory as a 'word'  it  will  occupy  two  bytes: the most significant
  235. (rightmost,  or  upper)  byte  will  read  zero  (0),  and  the  least
  236. significant (leftmost, or lower) will  be twelve (12). The distinction
  237. between 'byte' and 'word' is important, and must be used with care.
  238.  
  239.  
  240.                            - Breakpoints -
  241.  
  242. These clever devices  will  stop  the  emulation  when  a register has
  243. reached a pre-determined value. In  fact,  emulation  will halt when a
  244. particular 'expression' has occured. This could  be when 'X > 1024' or
  245. when 'A=2', for example. The possible combinations are,
  246.  
  247. Registers       Comparisons                         Equivalent instr.
  248. A               >          Greater than             bgt and bhi
  249. B               <          Less than                blt and blo
  250. X               >=         Greater than or equals   bge
  251. Y               <=         Less than or equals      ble
  252. S               =          Equals                   beq
  253. U               <>  or !=  Not equals               bne
  254. PC
  255. Sb
  256.  
  257. Note: The 'Sb' breakpoint would not normally be used, as it can not be
  258. altered from within the virtual processor.
  259.  
  260.    To create a new breakpoint, just hit 'New'. This will duplicate the
  261. currently selected breakpoint.  You  then  have  access  to  the other
  262. gadgets to modify it accordingly. Whenever  a  change is made, it will
  263. be seen in the list. The  buttons  along  the bottom of the window are
  264. self-explainatory, but there are a couple of further notes.
  265.  
  266.    The 'enable' check  box  only  applies  to  the  currently selected
  267. breakpoint. This  is  visible  from  the  list  box,  as  any disabled
  268. breakpoints are shown in blue.  These  breakpoints  will not be active
  269. whilst running the emulator, but can  be  brought back to life without
  270. having to re-program them.  To  disable  all  the breakpoints just de-
  271. select the 'Use Breakpoints' check  box.  Although nothing will appear
  272. to happen, none of the  breakpoints  listed  (whether enabled, or not)
  273. will halt the program.
  274.  
  275.    Finally, a note about the two forms of greater than. The difference
  276. between 'bgt' (branch greater than) and  'bhi' (branch higher) is that
  277. 'bhi' ignores the sign bit (i.e.  it  is an unsigned operator), whilst
  278. bgt considers it. 'blo' is also an unsigned operator.
  279.  
  280. For example:
  281.         128 is bhi than 2
  282.         but 128 is not bgt 2, because, when signed, 128 is -128
  283.  
  284.  
  285.                              - Symbols -
  286.  
  287. To make memory access easier,  the  emulator  supports a symbol table.
  288. This is nothing more complex than a  look-up table featuring a list of
  289. symbols (or labels, if you prefer) and a number that is equivalent.
  290.  
  291.    To add a new  symbol,  simple  press  the  'Add'  button. This will
  292. create a new symbol.  By  default  this  is  called 'Unlisted', and is
  293. assign to zero (0). You can then  alter these values as desired in the
  294. requesters at the bottom  (labelled  'address'  and 'label'), pressing
  295. return to set each value.
  296.  
  297.    The buttons on the bottom of the window have obvious functions. One
  298. feature that has extra functionality however, is the 'Load' button. If
  299. a symbol table already  exists  in  memory,  it  is  possible to merge
  300. another symbol file with the one in  memory up to the memory limit (30
  301. symbols in  the  shareware  version).  A  requester  will  be  opened,
  302. prompted you for an answer, whether you want to merge the symbol files
  303. or not.
  304.  
  305.  
  306. Important Note: When a symbol list  exists,  it is searched whenever a
  307. text requester is used. That means that instead of entering an address
  308. as '$4e20' into the PC register  (for  example),  you can use a symbol
  309. (like mc_start) from the symbol table.
  310.  
  311.  
  312.                               - About -
  313.  
  314. Now really...do I need to explain this?
  315.  
  316.  
  317.                    -- What I did to speed it up. --
  318.  
  319. * Used the Amigas status  register  as  the  equivalent in the 6809. I
  320. could do this easily because the main  4  flags (NZVC) are in the same
  321. bit positions on both processors. The  only time they are manipulating
  322. individually is on the instructions ANDCC and ORCC, so I wrote code to
  323. change my style of CCR to that  of  the actual 6809. This code is also
  324. used when the CCR  is  PUSHed  or  PULLed  from  the  stack,  as it is
  325. possible to change the entire CCR by  pulling the 'wrong' value of it.
  326. However, in future versions I may  have  to  vary this code, as higher
  327. processors require the use of GetCC  and  PutCC, that will take longer
  328. to execute than specific code.
  329.  
  330. * Used macros  instead  of  subroutines  (in  most  cases  except, for
  331. example, the index addressing  mode  where  the resultant code becomes
  332. obtuse  and  takes  instructions   out   of   range   for  the  branch
  333. instructions).
  334.  
  335. * Used self-modifying code  to  create  breakpoints and change between
  336. 'Step' and 'Exec' modes. This is  very  bad practise, and is the first
  337. time I've done it since...well, the last time!
  338.  
  339. * Used equivalent 68K instructions at all times, because this sets the
  340. appropiate flags, saving perhaps an extra cycle.
  341.  
  342. * Kept all the virtual registers  in  the 6809's registers. i.e. the A
  343. reg was held in  d2  AT  ALL  TIMES.  So  no  clock cycles were wasted
  344. reading data from memory.
  345.  
  346. * Used .b and .w to save  code  checking  for overflow etc. I'm glad I
  347. read the manual before I starting implementing this :-) But it's still
  348. my weakest area.
  349.  
  350. * Separate code routines for decoding an instruction during emulation,
  351. and reading it in  disassembly.  I  could  have  modularised  it (as a
  352. *real* software engineer would have) but  it would have slowed it down
  353. too much. As it is, I can change the macros if I wanted, but the first
  354. version of the disassembler was  in  AMOS,  so  I  thought it would be
  355. quicker just to port it! Besides - the 6809 is not going to be updated
  356. is it!
  357.  
  358. * Used a jump table consisting of 'bra xxx' instructions. Although two
  359. jumps take extra time, it also  reduces the instruction decode routine
  360. to the equivalent of:
  361.  
  362.         Goto OP_CODE * 4
  363.  
  364.   Which saves a great deal time over,
  365.  
  366.         If OP_CODE = 0
  367.                 Goto 232
  368.         Else If OP_CODE = 1
  369.                 Goto 353
  370.         ...
  371.  
  372.  
  373.  
  374.                  -- What I WILL do to speed it up. --
  375.  
  376. * Refine my macros. Remove any  redundant code. Re-generate the source
  377. (with  macros  replaced)  and   produce   tailored  versions  of  each
  378. instruction. This will take some time,  and  may only save a few clock
  379. cycles so this is quite low on my priority list :-(.
  380.  
  381. * Buy a new computer with a 68040 in it :-) Learn a bit more 68K code,
  382. as I'm hoping I'll an  instruction  on  later  processors that lets me
  383. define an area of memory (i.e. that  of my pseudo text screen) and get
  384. the processor to call my  routine  (interuppt style) when an attempted
  385. access is made.
  386.  
  387.  
  388.              -- What I WOULD LIKE to do to speed it up --
  389.                    (by I am prevented by doing it)
  390.  
  391. * Read a word from any memory location - even if it DOESN'T fall on an
  392. even word boundary. It's my only niggle about the 68K (that I've found
  393. so far).
  394.  
  395.  
  396.                           -- New Features --
  397.  
  398. Software is never finished before it's out of date! I believe that. As
  399. a consequence, I  am  hoping  (time  and  workload  permitting) to add
  400. several new features  to  the  emulator.  They  include,  but  are not
  401. limitted to:
  402.  
  403.  
  404. Keyboard, joystick and mouse (!) input.
  405. Memory-mapped  I/O  triggers   (executes   user-programmed  code  when
  406. specific memory areas are used)
  407. The Dragon graphic modes
  408. Different ASM modules holding optimised assembler for different
  409. processor configurations.
  410. Full menu  bar  allowing  access  to  more  'little'  options  (search
  411. routines, hex calculator etc).
  412.  
  413.  
  414.    At this stage, that is purely a  wish  list. But, as time arises, I
  415. will sit down and work on each  feature. But I will only be encouraged
  416. to do so knowing that somebody else  is  using the product. And if you
  417. are, you must register...
  418.  
  419.                           -- Registering --
  420.  
  421. Let's face it. This is mean package! And you can't expect me to do all
  422. this work for nostalgia, can you? So,  if you use this system for more
  423. than 30 days, or find it useful, you are encouraged to register it for
  424. the measily sum of £5. This gets you the complete source (to both Amos
  425. and assembler parts) and the latest version of the system itself.
  426.  
  427.  
  428. Q. Where do I send my money?
  429. A. Steven Goodwin
  430.    105 St. Johns Road
  431.    Clacton-on-Sea
  432.    Essex CO16 8DB
  433.  
  434. Q. What do I say?
  435. A. Try printing this off....
  436.    (or copying the relevant bits if you're without a printer)
  437.  
  438. o/_________________________ CUT HERE ________________________________
  439. O\
  440.  
  441. Your Name:_______________
  442. Address  :_______________
  443.           _______________
  444.           _______________
  445.           _______________
  446.  
  447. Hi Mr. Steven Goodwin,
  448.  
  449.    I would like to register my copy of the 6809 Emulator because,
  450.  
  451. a) There's no high pressure sales talk...
  452. b) I want access to the good bits you left out!
  453. c) I don't believe your self-modifying assembler will confuse me!
  454. d) It brought back some good memories...before the days of the Guru!
  455. e) I have a tremendous guilt complex!
  456. f) All of the above                         (circle as appropriate)
  457.  
  458.    I enclose a cheque/postal order for £5 (which includes P&P) because
  459. I'm a kind hearted  soul  whos  cares  about  the  people  who make my
  460. software.
  461.  
  462.    Thanks very much,
  463.  
  464.  
  465.       Name ________________ (not completely necessary, but ties up the
  466.                              letter nicely)
  467.  
  468.  
  469. o/_________________________ CUT HERE ________________________________
  470. O\
  471.  
  472.  
  473. That's all folks!!!! See you on the next release...
  474.  
  475.  
  476.  
  477.